<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/include.jsp"%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<script type="text/javascript" src='<s:url value="/scripts/CustomTreeUI.js" includeParams="none"/>'></script>
<link rel="stylesheet" type="text/css" href='<s:url value="/scripts/column-tree.css" includeParams="none"/>'/>

</head>
<body>
<script>

	function onClick(){

		var Tree = Ext.tree;
   		var tree = new Tree.TreePanel({
       
        autoScroll:true,
        animate:true,
        enableDD:true,
        containerScroll: true,
        rootVisible:false, 
        
        loader: new Tree.TreeLoader({
          			 dataUrl:'<s:url namespace="/function" action="list!getFS.action"/>'
            		
        })
    });


    // set the root node
    var root = new Tree.AsyncTreeNode({
        text: '功能',
        draggable:false,
        id:'-1'
    });
    tree.setRootNode(root);
	//tree.on("click",function(n){Ext.get("fpi").dom.value=n.id;Ext.get("fpn").dom.value=n.text;alert(tree.getChecked().length+'');});
	//
	var win = new Ext.Window({
	                //applyTo     : 'hello-win',
	                title:"选择父功能",
	                layout      : 'fit',
	                width       : 600,
	                height		:400,
	                closable:false, 
	                closeAction :'close',
	                modal:true, 
	                plain       : true,
	                items:tree,
	                buttons: [
	                {
	                    text     : '确定',
	                    disabled : false,
	                    handler  :function(){
	                    var n = tree.getSelectionModel().getSelectedNode();
	                    if (n == null){
	                     alert("必须选择一个节点");
	                     return;
	             		}
	                    Ext.get("fpi").dom.value=n.id;
	                    Ext.get("fpn").dom.value=n.text;
	                    
	                    win.close();}
	                },
	                {
	                    text     : '取消',
	                    disabled : false,
	                    handler  :function(){
	                    Ext.get("fpi").dom.value='';Ext.get("fpn").dom.value='';
	                    win.close();}
	                }]
	            });
    // render the tree
    win.show();
	}
  // root.expand();
	/*
	Ext.onReady(function (){
		alert(Ext.onReady);
		alert(document.getElementById('parentFunctionButton'));
		alert(Ext.get("parentFunctionButton"));
		//Ext.get("parentFunctionButton").on("click",function(){});
	});
	*/
	Ext.onReady(initListTree);
	function initListTree(){
		
		var treeLoader = new Ext.tree.TreeLoader({dataUrl:'<s:url namespace="/function" action="list!getChildren.action"/>'
			});
		var treeRoot = new Ext.tree.AsyncTreeNode({
			id:'-1'
			});
		var treePanel = new Ext.tree.ColumnTree({
			columns:[{header:'父功能',dataIndex:'name'},
					{header:'功能名称',dataIndex:'name'},
					{header:'功能号',dataIndex:'name'},
					{header:'功能地址',dataIndex:'name'},
					{header:'是否叶子',dataIndex:'name'},
					{header:'是否过滤',dataIndex:'name'},
					{header:'是否显示',dataIndex:'name'},
					{header:'操作',dataIndex:'name'}],
					
			rootVisible:false,
			loader:treeLoader,
			root:treeRoot
		});
		//
		//treePanel.render('tree-list');
		/*
		var searchBt = Ext.get('searchBt');
		searchBt.on('click',function(e){
			e.preventDefault();
			//
			Ext.get('funForm').select('input').each(function(field){
				treeLoader.baseParams[field.dom.name] = field.dom.value;
			});
			
			treeLoader.load(treeRoot);
		});
		*/
	}
</script>

<div class="main">
<div class="main_title"><b>你当前的位置</b>：功能管理-功能列表</div>
	<s:form id="funForm"  namespace="/function" action="list">
	<s:hidden name="pageSize" id="pageSize"/>
	<table align="center"  cellpadding="1" cellspacing="1" class="search">

	<s:hidden id="fpi" name="function.parent.id"/>
	
	<tr class="listr2">
		<td align="right" class="listr6">功能名</td>
		<td align="left" class="listr5"><s:textfield id="function_name" name="function.name" cssClass="searchInput"/></td>	
		<td align="right" class="listr6">功能号</td>
		<td align="left" class="listr5"><s:textfield name="function.functionCode" cssClass="searchInput"/></td>
	</tr>
	<tr class="listr2">
		<td align="right" class="listr6">功能地址</td>
		<td align="left" class="listr5"><s:textfield name="function.addresss" cssClass="searchInput"/></td>
		<td align="right" class="listr6">父功能</td>
		<td align="left" class="listr5"><s:textfield id="fpn" name="function.parent.name" cssClass="searchInput"/>&nbsp;<a href="javascript:onClick();"  id="parentFunctionButton" ><font color="#273DAC"><I>点击选择</I></font></a></td>
	</tr>
	<tr style="height:30px;background:#FDFAF2;padding-top:3px;">
		<td align="center" colspan="4">
			<s:submit id="searchBt" cssClass="btn" onmouseover="this.className='btn_hover'" onmouseout="this.className='btn'" value="查 询" />
    		<input name="Submit9" type="reset" class="btn"  onmouseover="this.className='btn_hover'" onmouseout="this.className='btn'" value="重 置" />
		</td>
	</tr>
</table>
 </s:form>
<div class="botton">
	<s:form namespace="/functon" action="addOrUpdate!input.action">
		<s:hidden name="function.parent.id"/>
		<input type="submit" class="add" onmouseover="this.className='add_hover'" onmouseout="this.className='add'" value="新增根"></input>
	</s:form>
</div>
<table align="center"  cellpadding="1" cellspacing="1" class="tablelist">
  <tr class="toptitle">
				<td>
					父功能
				</td>
				<td>
					功能名称
				</td>
				<td>
					功能号
				</td>
				<td>
					功能地址
				</td>
				<td>
					枝/叶子
				</td>
				<td>
					功能类型
				</td>
				<td>
					是否过滤
				</td>
				<td>
					是否显示在菜单
				</td>
				<td>
					操作
				</td>
			</tr>
			<s:iterator value="page.res" status="status">
				<s:if test="#status.even">
				 <tr class="listr1" onmouseover="this.className='listr3'" onmouseout="this.className='listr1'">
				</s:if>
				<s:else>
				 <tr class="listr2" onmouseover="this.className='listr3'" onmouseout="this.className='listr2'">
				</s:else>
					<td>
						&nbsp;
						<s:property value="parentName" />
					</td>
					<td>
						&nbsp;
						<s:property value="name" />
					</td>
					<td>
						&nbsp;
						<s:property value="functionCode" />
					</td>
					<td>
						&nbsp;
						<s:property value="addresss" />
					</td>
					<td>
						&nbsp;
						<s:if test="leaf">是</s:if>
						<s:else>否</s:else>
					</td>
					<td>
						&nbsp;
						<s:property value="functionType" />
					</td>
					<td>
						&nbsp;
						<s:if test="filter">是</s:if>
						<s:else>否</s:else>
					</td>
					<td>
						&nbsp;
						<s:if test="show">是</s:if>
						<s:else>否</s:else>
					</td>
					<td>
						&nbsp;
						<s:url id="modifyUrl" namespace="/function"
							action="addOrUpdate!input" includeParams="false">
							<s:param name="function.id">
								<s:property value="id" />
							</s:param>
							
						</s:url>
						<s:url id="viewUrl" namespace="/function" includeParams="false"
							 action="view">
							<s:param name="function.id">
								<s:property value="id" />
							</s:param>
						</s:url>
						<s:url id="deleteUrl" namespace="/function" includeParams="false" 
							action="list!deleteFunction">
							<s:param name="function.id">
								<s:property value="id" />
							</s:param>
						</s:url>
						<s:url id="addSubUrl" namespace="/function" includeParams="false"
							action="addOrUpdate!input.action">
							<s:param name="function.parent.id">
								<s:property value="id" />
							</s:param>
						</s:url>
						<s:if test="leaf">
						
						</s:if>
						<s:else>
							<s:a href='%{addSubUrl}'>添加子功能</s:a>
						</s:else>
						
						<s:a href='%{modifyUrl}'>修改</s:a>
						<s:a href='%{viewUrl}'>查看</s:a>
						<s:a href='%{deleteUrl}'>删除</s:a>
					</td>
					
				</tr>
			</s:iterator>
			<s:set  var="totle" scope="request" value="page.count"/>
		<s:set  var="pageSize" scope="request" value="pageSize"/>
		<%
					Integer count = (Integer) request.getAttribute("totle");
					Integer pageSize = (Integer) request.getAttribute("pageSize");
		%>
		
			<tr>
			<td class="listr4" colspan="9">
				
				<pg:pager  url="list.action" items='<%=count.intValue()%>'
					maxPageItems='<%=pageSize%>' export="currentPage=pageNumber">
					<pg:param name="function.name" />
					<pg:param name="function.addresss" />
					<pg:param name="function.parent.id" />
					<pg:param name="pageSize" />
					<pg:index export="pages">
						<table>
						<tr>
						<td>
							当前<b class="fontred"><%= currentPage%></b>/<%=pages%>页&nbsp;&nbsp;&nbsp;&nbsp;
						</td>
						<td>
						<pg:first>
							<a href="<%=pageUrl%>&pageNo=<%=pageNumber%>">首页</a>
						</pg:first>
						</td>
						<td>	
						<pg:prev>
							<a href="<%=pageUrl%>&pageNo=<%=pageNumber%>">上一页</a>
						</pg:prev>
						</td>
						<td>
						<pg:pages>
							<%
								if (currentPage == pageNumber) {
							%>
							<font color="red"><%=pageNumber%></font>
							<%
								} else {
							%>
							<a href="<%=pageUrl%>&pageNo=<%=pageNumber%>"><%=pageNumber%></a>
							<%
								}
							%>
						</pg:pages>
						</td>
						<td>
						<pg:next>
							<a href="<%=pageUrl%>&pageNo=<%=pageNumber%>">下一页</a>
						</pg:next>
						</td>
						<td>
						<pg:last>
							<a href="<%=pageUrl%>&pageNo=<%=pageNumber%>">末页</a>&nbsp;&nbsp;&nbsp;&nbsp;
						</pg:last>
						</td>
						
						<td>
							&nbsp;
						</td>
						<td style="padding-left: 10px;">
							每页显示的记录数
						</td>
						<td>
							<input type="text" class="inputDftText" value="<%=pageSize %>" onchange="Ext.get('pageSize').dom.value=this.value;Ext.get('funForm').dom.submit();"/>
						</td>
						<td>
							条
						</td>
						<td>
							&nbsp;
						</td>
						</tr>
						</table>
					</pg:index>

				</pg:pager>
				</td>
				</tr>
		</table>		
</div>
</body>